package com.dpp.service.impl;

import com.dpp.entity.ShopInfo;
import com.dpp.mapper.ShopInfoMapper;
import com.dpp.result.Result;
import com.dpp.service.ShopService;
import com.dpp.vo.ShopVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopInfoMapper shopInfoMapper;
    @Override
    public Result selectAll() {
        ShopVo shopVo = new ShopVo();
        List<ShopInfo> shopInfoList= shopInfoMapper.selectAll();
        Map<String, List<ShopInfo>> shopInfos = shopInfoList.stream().collect(Collectors.groupingBy(ShopInfo::getShopLocation));
        for (String shopLocation : shopInfos.keySet()) {
            if(shopLocation.equals(ShopVo.eastBathFirst)){
                shopVo.setEastBathFirstFloor(shopInfos.get(shopLocation));
            } else if (shopLocation.equals(ShopVo.eastBathSecond)) {
                shopVo.setEastBathSecondFloor(shopInfos.get(shopLocation));
            } else if (shopLocation.equals(ShopVo.eastServiceFirst)) {
                shopVo.setEastServiceFirstFloor(shopInfos.get(shopLocation));
            }else if (shopLocation.equals(ShopVo.eastServiceThird)) {
                shopVo.setEastServiceThirdFloor(shopInfos.get(shopLocation));
            }
        }
        return Result.success(shopVo);
    }
}
